package com.jf.identity.service.impl;

import com.jf.identity.entity.Device;
import com.jf.identity.entity.ExamBaseParam;
import com.jf.identity.holder.ExamBaseParamHolder;
import com.jf.identity.service.DeviceInfoService;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by x on 2018/4/14.
 */
@Service
public class DeviceInfoServiceImpl implements DeviceInfoService {
    @Resource
    private ExamBaseParamHolder examBaseParamHolder;
    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public boolean insertDeviceInfo(List<Device> devices) {
        ExamBaseParam examBaseParam = examBaseParamHolder.getExamBaseParam();
        ExamBaseParam.isBlank(examBaseParam);
        examBaseParam.validate(ExamBaseParam.ORGCODE);
        for (Device device : devices) {
            device.setExamBaseParam(examBaseParam);
            device.setTimestamp(new Date());
            mongoTemplate.insert(device);
        }
        return true;
    }
}














